/* test_init.c
 test for init:
save
load
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "buddy_system.h"
#include "defines.h"

//	state=disk_init(INIT_TYPE_CREATE, g_image, NULL, "buddy.log", 50*1024*64-DISK_IMAGE_SIZE-DISK_SEG_SIZE);
int main()
{
	char* g_image;
	STATE state;


	g_image=(char*)mp_alloc(IMAGE_K_SIZE*1024);
	sync_init("/tmp/disk", "sync.log");
	state=disk_init(INIT_TYPE_CREATE, g_image, NULL, "buddy.log", 50*1024*64-DISK_IMAGE_SIZE-DISK_SEG_SIZE);

	disk_show();

	disk_exit();
	state=sync_write(DISK_IMAGE, g_image, IMAGE_K_SIZE*1024);
	if (state==-1) printf ("state error\n");
	mp_free(g_image);



	g_image=(char*)mp_alloc(IMAGE_K_SIZE*1024);
	sync_read(DISK_IMAGE, g_image, IMAGE_K_SIZE*1024);
	state=disk_init(INIT_TYPE_LOAD, g_image, NULL, "buddy.log", 50*1024*64-DISK_IMAGE_SIZE-DISK_SEG_SIZE);
	
	disk_show();
		
	disk_exit();
	state=sync_write(DISK_IMAGE, g_image, IMAGE_K_SIZE*1024);
	sync_exit();
	mp_free(g_image);

	return 0;
}
